﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;
using System.Collections;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TWBCP02 : UIWBBST
    { 
        ITXEXRPT ITXEXRPT;
        public TWBCP02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBBST();
            this.DataContext = MV; 
            InitializeComponent(); 
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            base.Window_Loaded(sender, e);
        } 
        private void txtART_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                this.Focus();
                QueryCommand(null, null);
            } 
        }
        /// <summary>
        ///  根据品种，色号进行模糊查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {

            DataSet Result;
            DataSet Return = new DataSet();
            DataRow dwData = null;   
            dwData =TBMain.NewRow();
            dwData["WBBART"] = ART;
            dwData["WBBFARBE"] = FARBE;
            dwData["WBBLO"] = LO;
            dwData["WBBLB"] = LB;
            try
            { 
                Result = TMV.QueryWBBST(dwData, 19);
                MergeData(Result, true, true);//查询结果在TBMain表，位于Setprod. WBBST，vwMaster是这个内容的视图，也就是这个表。不过，当鼠标定位等的时候，vwMaster会捕捉到当前记录，

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        } 
        private void ExcelCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = new DataSet();
                ITXEXRPT.dsSource.Merge(MV.SetProd);
                //ITXEXRPT.dsSource.Merge(Se.Env);

                ITXEXRPT.DocType = "JLTWB02";

                ITXEXRPT.strExcelFile = @"JLT\JLTCPWB02.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

    }
}
